<template>
	<view class="mainbgc">
		<header-top :messageInfo="{typeFlag:true,message:'店铺信息修改',liner:false}"></header-top>
		<view class="mainpadding margin_top ffffff">
			<view class="inputbox">
				<view class="flexleft flex1">
					<view class="strongtext margin_right">店铺名称：</view>
				</view>
				<view class="itembox">
					<input type="text" placeholder="请输入仓库名称" v-model="ckname">
				</view>
			</view>
			<view class="inputbox margin_top">
				<view class="flexleft flex1">
					<view class="strongtext margin_right">店铺logo：</view>
				</view>
			</view>
			<view class="margin_top flexcenter">
				<view class="upimagebtn radius flexcenter" @click="uploadImg">
					<!-- 未上传 -->
					<view class="noimage"  v-show="!upImg">
						<image src="../../static/image/system/bigadd.png" mode=""></image>
					</view>
					<!-- 已上传 -->
					<view class="image radius" v-show="upImg">
						<image class="radius" :src="upImg" mode=""></image>
					</view>
				</view>
			</view>
			<view class="inputbox margin_top">
				<view class="flexleft flex1">
					<view class="strongtext margin_right">客服电话：</view>
				</view>
				<view class="itembox">
					<input type="text" placeholder="请输入客服电话" v-model="kfphone">
				</view>
			</view>
			<view class="inputbox margin_top">
				<view class="flexleft flex1">
					<view class="strongtext margin_right">公司电话：</view>
				</view>
				<view class="itembox">
					<input type="text" placeholder="请输入公司电话" v-model="gsphone">
				</view>
			</view>
			<view class="inputbox margin_top">
				<view class="flexleft flex1">
					<view class="strongtext margin_right">联系人：</view>
				</view>
				<view class="itembox">
					<input type="text" placeholder="请输入联系人" v-model="lxperson">
				</view>
			</view>
			<view class="inputbox margin_top">
				<view class="flexleft flex1">
					<view class="strongtext margin_right">公司地址：</view>
				</view>
				<view class="itembox">
					<input type="text" placeholder="请输入公司地址" v-model="gsaddress">
				</view>
			</view>
		</view>
		<view class="mainpadding" @click="submit">
			<view class="surebtns flexcenter margin_top">确认</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				upImg: '',
				ckname: '', //仓库名称
				kfphone: '', //客服电话
				lxperson: '', //联系人
				gsphone: '', //公司电话
				gsaddress: '', //公司地址
			}
		},
		onLoad() {
			this.init()
		},
		methods: {
			init(){
				httpRequest.request('appapi/manage/user/company_info', 'POST', {
				}, false, false, true).then(res => {
					if (res.code == 1) {
						this.gsaddress = res.data.company_address
						this.ckname  = res.data.company_name; //公司名称
						this.upImg = res.data.company_logo; //LOGO
						this.gsphone = res.data.company_phone; //公司电话
						this.kfphone = res.data.mobile
						this.lxperson = res.data.nickname
					}
				})
			},
			uploadImg() {
				let _this = this;
				// let upImgs = _this.upImg;
				// let num = 3 - upImgs.length;
				// if (num <= 0) {
				// 	return false;
				// }
				uni.showActionSheet({
					itemList: ['相机', '相册'],
					success: function(res) {
						console.log(res)
						// 选择相机走0
						if (res.tapIndex == 0) {
							httpRequest.chooseImage(1, ['camera']).then(res => {
								for (var i = 0; i < res.length; i++) {
									_this.uploadImageService(res[i], _this.upImg)
								}
							}).catch(err => {});
						}
						// 选择相册走1
						if (res.tapIndex == 1) {
							httpRequest.chooseImage(1, ['album']).then(res => {
								for (var i = 0; i < res.length; i++) {
									console.log(res[i])
									_this.uploadImageService(res[i], _this.upImg)
								}
							}).catch(err => {});
						}
					},
					fail: function(res) {}
				});
			},
			// 详情转载
			uploadImageService(url) {
				console.log(url, 888)
				let _this = this;
				httpRequest.uploadFile('api/common/upload', url).then(res => {
					// let image_item = res.fullurl;
					// upImg.push(image_item);
					this.upImg = res.fullurl
				}).catch(err => {});
			},
			submit() {
				httpRequest.request('appapi/manage/user/company_info_edit', 'POST', {
					// 传参
					company_name: this.ckname, //公司名称
					company_logo: this.upImg, //LOGO
					company_phone: this.gsphone, //公司电话
					company_address: this.gsaddress, //公司地址
					mobile:this.kfphone,
					nickname:this.lxperson
				}, false, false, true).then(res => {
					httpRequest.toast(res.msg)
					if (res.code == 1) {
						setTimeout(()=>{
							uni.navigateBack({
								delta:1
							})
						},1000)
						// this.userlist = res.data.user_info
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.flex1 {
		flex: 3;
	}

	.inputbox {
		display: flex;
		align-items: flex-start;
		justify-content: space-between;
	}

	.strongtext {
		line-height: 42rpx;
	}

	.itembox {
		flex: 7;
		width: 100%;
		padding-bottom: 20rpx;
		border-bottom: 1rpx solid rgba(153, 153, 153, 0.06);
	}

	.upimagebtn {
		width: 142rpx;
		height: 142rpx;
		border: 1rpx solid rgba(202, 202, 202, 0.6);
		background-color: #f3f3f3;

		.image {
			width: 100%;
			height: 100%;

			image {
				width: 100%;
				height: 100%;
			}
		}
	}

	.noimage {
		width: 72rpx;
		height: 72rpx;

		image {
			width: 100%;
			height: 100%;
		}
	}
</style>
